package com.jinglvhuanjing.app.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

    //获取当前日期
    Calendar calendar = Calendar.getInstance();

    Date date = calendar.getTime();

    public static final int WEEKDAYS = 7;
    public static String[] WEEK = {
            "星期天",
            "星期一",
            "星期二",
            "星期三",
            "星期四",
            "星期五",
            "星期六"
    };

    /**
     * 日期变量转成对应的星期字符串
     *
     * @param date
     * @return
     */
    public static String DateToWeek(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int dayIndex = calendar.get(Calendar.DAY_OF_WEEK);
        if (dayIndex < 1 || dayIndex > WEEKDAYS) {
            return null;
        }
        return WEEK[dayIndex - 1];
    }

    public static String DateToYMD_HM(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");// 转换格式
        String time = sdf.format(date);
        return time;
    }

    public static String DateToYMD_HMsS(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss SSS");// 转换格式
        String time = sdf.format(date);
        return time;
    }

    public static String DateToYMD_HMs(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");// 转换格式
        String time = sdf.format(date);
        return time;
    }
}
